package com.wanmait.recycle.listener;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import com.wanmait.recycle.pojo.Admin;

public class SessionListener implements HttpSessionListener {

	//创建一个session自动调用
	
	public void sessionCreated(HttpSessionEvent e) {
		Admin admin = new Admin();
		admin.setId(1);
		admin.setIsSuper(true);
		admin.setName("zhangsan");
		admin.setEnable(true);
		admin.setPassword("000000");
		e.getSession().setAttribute("Admin", admin);
		
		/*ServletContext application = e.getSession().getServletContext();
		int onlineCount = (Integer)application.getAttribute("onlineCount");
		application.setAttribute("onlineCount", onlineCount+1);
*/		

	}

	//销毁session自动调用
	
	public void sessionDestroyed(HttpSessionEvent e) {
/*		ServletContext application = e.getSession().getServletContext();
		int onlineCount = (Integer)application.getAttribute("onlineCount");
		application.setAttribute("onlineCount", onlineCount-1);
*/		

	}

}
